﻿<%@ Page MasterPageFile="~/Site.Master" Language="C#" AutoEventWireup="true" CodeBehind="ShopDetailEdit.aspx.cs" Inherits="RabbitManage.UI.ShopDetailEdit" %>

<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
    


    <form id="form1" action="../Action/ShopDetailEdit.aspx" method="POST">
        
    <script type="text/javascript" src="/Share/js/city.js"></script>
    <script type="text/javascript">

        var namePass = true;

        function nameValidate() {
            var element = document.getElementById("inputName");
            var xhr = new XMLHttpRequest();
            xhr.open("post", "/Action/ShopValidate.aspx?NickName=" + element.value, true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
            xhr.send();
            document.getElementById("nameValidator").innerHTML = "<img src='/Share/image/wait.gif' width=20 />";

            xhr.onloadend = function () {
                // done
                if (xhr.responseText == "true") {
                    document.getElementById("nameValidator").style.color = "green";
                    document.getElementById("nameValidator").innerHTML = "√";
                    namePass = true;
                } else {
                    document.getElementById("nameValidator").style.color = "red";
                    document.getElementById("nameValidator").innerHTML = "×";
                    namePass = false;
                }
            };

        }

        form1.onsubmit = function (e) {
            // stop the regular form submission
            e.preventDefault();

            // collect the form data while iterating over the inputs
            var data = {};
            for (var i = 0, ii = form1.length; i < ii; ++i) {
                var input = form1[i];
                if (input.name) {
                    data[input.name] = input.value;
                }
            }

            // construct an HTTP request
            var xhr = new XMLHttpRequest();
            xhr.open(form1.method, form1.action, true);
            xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

            // send the collected data as JSON
            xhr.send(JSON.stringify(data));

            xhr.onloadend = function () {
                // done
                if (xhr.responseText == "true") {
                    window.location = "ShopDetail.aspx";
                } else {
                    alert(xhr.responseText);
                }
            };
        };
        
        function validate() {
            var pass = namePass;
            return pass;
        }

    </script>

    <section class="contact">

        <h3>商家信息编辑:</h3>
    <table>
<%--        <tr>
            <td>Name:</td>
            <td><%=item.Name %></td>
        </tr>
        
        <tr>
            <td>CellPhone:</td>
            <td><%=item.CellPhone %></td>
        </tr>
        
        <tr>
            <td>Mail:</td>
            <td><%=item.Mail %></td>
        </tr>--%>
        
        <tr>
            <td>店铺昵称:</td>
            <td>
                <input type="text" id="inputNickName" name="NickName" onblur="nameValidate();" value="<%=item.NickName %>" style="width: 500px;" />
            </td>
            <td id="nameValidator"></td>
        </tr>
        
        <tr>
            <td>运费说明:</td>
            <td>
               <textarea id="inputDiliveryCostDescription" name="DiliveryCostDescription" ><%=item.DiliveryCostDescription %>"</textarea>
            </td>
        </tr>
        <tr>
            <td>
                满包邮：
            </td>
            <td>
                <input type="text" id="inputFreeShipAt" name="FreeShipAt" value="<%=item.FreeShipAt %>" style="width: 40px; text-align: right;"  />
            </td>
        </tr>

        <tr>
            <td>发货地址:</td>
            <td>
                <select id="cmbProvince" name="Province" ></select>
                <select id="cmbCity" name="City"></select>
                <select id="cmbArea" name="Region"></select>
                <br/>
                <input type="text" id="inputDetail" name="Detail" style="width: 500px;" value="<%=item.Location.Detail %>"  />
            </td>
        </tr>
        
        <tr>
            <td>
                发货人：
            </td>
            <td>
                 <input type="text" id="inputContactName" name="ContactName" style="width: 120px;" value="<%=item.Location.ContactName %>" />
            </td>
        </tr>
        <tr>
            <td>
                电话：
            </td>
            <td>
                <input type="text" id="inputContactPhone" name="ContactPhone" style="width: 120px;" value="<%=item.Location.ContactPhone %>" />
            </td>
        </tr>
        <tr>
            <td>
                邮编：
            </td>
            <td>
                <input type="text" id="inputPostalCode" name="PostalCode" style="width: 120px;" value="<%=item.Location.PostalCode %>" />
            </td>
        </tr>

    </table>
        
    <input type="submit" value="保存" onclick="return validate();" />

        <script type="text/javascript">
            addressInit('cmbProvince', 'cmbCity', 'cmbArea', '<%=item.Location.Province %>', '<%=item.Location.City %>', '<%=item.Location.Region %>');
        </script>
        
    </section>
        
    </form>
</asp:Content>
